package com.cxf.windex.rest.minab;

import com.cxf.windex.base.constant.UserConstant;
import com.cxf.windex.base.msg.ObjectRestResponse;
import com.cxf.windex.base.msg.TableResultResponse;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.biz.BResourcesBiz;
import com.cxf.windex.entity.BMeterials;
import com.cxf.windex.entity.BResouces;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: business_needs
 * @description:
 * @author: chenxf
 * @create: 2018-10-16 17:36
 **/
@Api(tags = {"村广通[小程序-商] - 资源方接口"})
@Controller
@RequestMapping("userb/resources")
public class BResourcesController extends BaseRestController<BResourcesBiz,BResouces> {
  @ApiOperation(value = "查询资源", notes = "查询资源")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "limit", value = "记录数 默认10",   paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "offset", value = "页码 默认 1",   paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "orderStr", value = "排序 默认desc", paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "provice", value = "省",   paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "city", value = "市",   paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "county", value = "区县",   paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "town", value = "乡镇",   paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "type", value = "村长 / 群主",   paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "name", value = "资源名称",   paramType = "query", dataType = "String")
  })
  @RequestMapping(value = "/list", method = RequestMethod.GET)
  @ResponseBody
  public TableResultResponse<BResouces> list(
      @RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1") int offset,
      @RequestParam(defaultValue = "desc") String orderStr,String name,String provice,String city,String county,String town,String type) {
    List<BResouces> items = baseBiz.list(limit, offset, orderStr,name, provice, city, county,UserConstant.FW_NORMAL,type,town);
    PageInfo<BResouces> pageInfo = new PageInfo<>(items);
    return new TableResultResponse<>(Integer.parseInt(String.valueOf(pageInfo.getTotal())),
        offset, limit,
        items);
  }

  @ApiOperation(value = "id查询资源", notes = "id查询资源")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "ids", value = "记录数 默认10", required = false, paramType = "query", dataType = "String")
  })
  @RequestMapping(value = "/idslist", method = RequestMethod.GET)
  @ResponseBody
  public ObjectRestResponse idslist(String ids) {
    List<BResouces> items = baseBiz.idsList(ids);
    return new ObjectRestResponse("查询成功").rel(true).result(items);
  }
}
